home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / extdrv / src / misc.c < prev    next >
C/C++ Source or Header  |  1994-11-16  |  2KB  |  130 lines

  1. #include "extdrv.h"
  2. #include "file.h"
  3. #include "ctype.h"
  4. #include "dir.h"
  5. #include "buffer.h"
  6. #include "dos.h"
  7. #include "extern.h"
  8.  
  9. extern char data_buf[];
  10.  
  11. void get_path(char *path)
  12. {
  13.     char *s;
  14.  
  15.     s = strrchr(path, '\\');
  16.     if (s[1] == '.'  &&  s[2] == '\0'){
  17.         if (s != path)
  18.             s[0] = '\0';
  19.         else
  20.             s[1] = '\0';
  21.         return;
  22.     }
  23.     if (s[1] == '.'  &&  s[2] == '.'  &&  s[3] == '\0'){
  24.         if (s != path){
  25.             s[0] = '\0';
  26.             s = strrchr(path, '\\');
  27.         }
  28.         if (s != path)
  29.             s[0] = '\0';
  30.         else
  31.             s[1] = '\0';
  32.     }
  33. }
  34.  
  35. void splitPath(char *path, char *name)
  36. {
  37.     char *s;
  38.  
  39.     s = strrchr(path, '\\');
  40.     strcpy(name, s + 1);
  41.     if (s == path)
  42.         s[1] = '\0';
  43.     else
  44.         s[0] = '\0';
  45. }
  46.  
  47. u_char *strrchr(u_char *s, u_char ch)
  48. {
  49.     u_char *p;
  50.     
  51.     p = (u_char *)NULL;
  52.     while (*s != '\0'){
  53.         if (issjis1(s[0]) && issjis2(s[1]))
  54.             s++;
  55.         else if (*s == ch)
  56.             p = s;
  57.         s++;
  58.     }
  59.     return (p);
  60. }
  61.  
  62. hasWild(char *s)
  63. {
  64.     for (; *s != '\0'; s++){
  65.         if (*s == '?'  ||  *s == '*')
  66.             return (TRUE);
  67.     }
  68.     return (FALSE);
  69. }
  70.  
  71. void expand(char *s, char *t)
  72. {
  73.     int n;
  74.  
  75.     strcpy(t, "           ");
  76.     if (s[0] == '.'){
  77.         t[0] = '.';
  78.         if (s[1] == '.')
  79.             t[1] = '.';
  80.         return;
  81.     }
  82.     n = 8;
  83.     while (*s != '\0'){
  84.         if (*s == '*'){
  85.             s++;
  86.             while (--n >= 0)
  87.                 *t++ = '?';
  88.             break;
  89.         }
  90.         if (*s == '.'){
  91.             t += n;
  92.             break;
  93.         }
  94.         *t++ = *s++;
  95.         n--;
  96.     }
  97.     if (*s != '.')
  98.         return;
  99.     s++;
  100.     n = 3;
  101.     while (*s != '\0'){
  102.         if (*s == '*'){
  103.             while (--n >= 0)
  104.                 *t++ = '?';
  105.             break;
  106.         }
  107.         *t++ = *s++;
  108.         n--;
  109.     }
  110. }
  111.  
  112. match(char far *fname, char *pattern)
  113. {
  114.     int n;
  115.  
  116.     for (n = 0; n < 11; n++, fname++, pattern++){
  117.         if (*fname == *pattern)
  118.             continue;
  119.         if (*pattern == '?')
  120.             continue;
  121.         return (FALSE);
  122.     }
  123.     return (TRUE);
  124. }
  125.  
  126. u_long laddr(u_short off, u_short seg)
  127. {
  128.     return (((u_long)seg << 4) + (u_long)off);
  129. }
  130.